package com.perfect.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.perfect.feign.StockFeignService;
import com.perfect.mapper.OrderMapper;
import com.perfect.model.Order;
import com.perfect.service.OrderService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper,Order> implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private StockFeignService stockFeignService;

    @Override
//    @Transactional
    @GlobalTransactional
    public void generatorOrder(Order order) {


        //插入订单
        orderMapper.insert(order);

        //扣减库存
        stockFeignService.reduct("1");

        //业务异常
        int exception=1/0;
        System.out.println("完成下单");
    }

}
